;#############################
;命令：
;nasm -f elf64 day3_1bss_0int.asm -o main.o && gcc main.o -o main -lc -no-pie && ./main
;输出：
;Value in arr[0] is 10.
;Value in arr[1] is 9.
;Value in arr[2] is 8.
;Value in arr[3] is 7.
;Value in arr[4] is 6.
;Value in arr[5] is 5.
;Value in arr[6] is 4.
;Value in arr[7] is 3.
;Value in arr[8] is 2.
;Value in arr[9] is 1.
;#############################
extern printf

section .data
	msg: db `Value in arr[%d] is %d.\n`, 0

section .bss
	arr: resd 10

section .text
	global main

main:
	push rbp
	mov rbp, rsp

;########################################
	;赋值
	mov dword [arr + 4 * 0], 10
	mov dword [arr + 4 * 1], 9
	mov dword [arr + 4 * 2], 8
	mov dword [arr + 4 * 3], 7
	mov dword [arr + 4 * 4], 6
	mov dword [arr + 4 * 5], 5
	mov dword [arr + 4 * 6], 4
	mov dword [arr + 4 * 7], 3
	mov dword [arr + 4 * 8], 2
	mov dword [arr + 4 * 9], 1
;########################################

	;打印
	mov ebx, 0
	jmp compare

execute:
	mov rdi, msg
	movsxd rsi, ebx
	movsxd rdx, dword [arr + 4 * ebx]
	call printf

	inc ebx

compare:
	cmp ebx, 10
	jl execute

	mov eax, 0
	leave
	ret
